package com.ynny.test01.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ynny.test01.entity.Order;
import com.ynny.test01.entity.OrderVo;
import com.ynny.test01.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService{

    @Autowired
    OrderMapper orderMapper;

    @Override
    public PageInfo findAllOrders(OrderVo orderVo) {

        PageHelper.startPage(orderVo.getPageNum(),orderVo.getPageSize());

        List<Order> orders = orderMapper.selectAll(orderVo);

        PageInfo<Order> pageInfo = new PageInfo<>(orders);


        return pageInfo;
    }

    @Override
    public int addOrder(Order order) {
        return orderMapper.insert(order);
    }

    @Override
    public int editOrder(Order order) {
        return orderMapper.update(order);
    }

    @Override
    public int deleteOrder(int id) {
        return orderMapper.delete(id);
    }
}
